package cwnu.sapphire.com.controller;

import cwnu.sapphire.com.utils.TimeUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/api/time")
public class TimeController {

    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @GetMapping("/beijing")
    public Map<String, Object> getBeijingTime() {
        Map<String, Object> result = new HashMap<>();
        
        // 获取北京时间
        result.put("timestamp", TimeUtils.getCurrentTimestamp());
        result.put("formatted_time", dateFormat.format(TimeUtils.getBeijingTime()));
        result.put("timezone", TimeUtils.getBeijingTimeZone().getID());
        result.put("timezone_offset", TimeUtils.getBeijingTimeZone().getRawOffset() / 3600000); // 转换为小时

        return result;
    }
} 